Page({
  data: {
    latitude: 0,//地图初次加载时的纬度坐标
    longitude: 0, //地图初次加载时的经度坐标
    name: "" //选择的位置名称
  },
  onLoad: function () {
    this.moveToLocation();
  },
  //移动选点
  moveToLocation: function () {
    var that = this;

    // 打开地图选择位置
    wx.chooseLocation({
      success: function (res) {
        // res.name为地址名称
        console.log(res.name);
        //选择地点之后返回到原来页面
        let pages = getCurrentPages();//当前页面
        let prevPage = pages[pages.length - 2];//上一页面
        var address = prevPage.data.address;
        address.address = res.name;
        if (res.name) {
          prevPage.setData({
            customizeAddress: res.name,
          });
        } else {
          prevPage.setData({
            customizeAddress: "Customize Address Not Found",
          });
        }
        prevPage.setData({
          address: address,
          customizeLatitude: res.latitude,
          customizeLongitude: res.longitude,
        });



        wx.navigateBack({//返回
          delta: 1
        });
      },
      fail: function (err) {
        console.log(err);
      }
    });
  }
});
